/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.appspot.trick.it.admin.task;

import com.appspot.trick.it.admin.api.GaeArticleAPIService;
import com.appspot.trick.it.admin.controller.MainController;
import com.appspot.trick.it.admin.custom.ArticleTreeItem;
import com.appspot.trick.it.admin.model.ArticleModel;
import java.util.ArrayList;
import java.util.List;
import javafx.concurrent.Service;
import javafx.concurrent.Task;

/**
 *
 * @author takahara
 */
public class ArticleLoadListTask extends Service<List<ArticleTreeItem>> {

    private String folderId;


    /**
     * コンストラクタ
     *
     * @param folderId
     */
    public void run(String folderId) {
        this.folderId = folderId;
        this.restart();
    }

    @Override
    protected Task<List<ArticleTreeItem>> createTask() {
        return new Task<List<ArticleTreeItem>>() {

            @Override
            protected List<ArticleTreeItem> call() throws Exception {
                GaeArticleAPIService gaeService = new GaeArticleAPIService(MainController.getInstance().getSiteMstEntity());

                List<ArticleModel> childrensList = gaeService.getList(folderId);

                List<ArticleTreeItem> treeItemList = new ArrayList();
                for (ArticleModel child : childrensList) {
                    ArticleTreeItem treeItem = new ArticleTreeItem(child);
                    treeItemList.add(treeItem);
                }

                return treeItemList;
            }
        };

    }

}
